package com.hxh.utils
{
	import flash.geom.Point;
	
	public class Maths {
		
		public function Maths() { }
	
		public static function toDegree(rad:Number):Number{
			var RAD_TO_DEG:Number = 180 / Math.PI;
			return rad * RAD_TO_DEG;
		}
		
		public static function toRadian(deg:Number):Number{
			var DEG_TO_RAD:Number = Math.PI / 180;
			return deg * DEG_TO_RAD;
		}
		//Random value between 2 integers
		public static function randomInt(min:Number, max:Number):Number {
			var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
			return randomNum;
		}
		
		//Get the distance of 2 points in the xy-coords system
		public static function distanceTwoPoints(p1:Point, p2:Point):Number{
			return Math.sqrt(Math.pow(p2.x-p1.x,2) + Math.pow(p2.y-p1.y,2));
		}
		
		public static function slopeTwoPoints(p1:Point, p2:Point):Number{
			return (p2.y-p1.y)/(p2.x-p1.x);
		}
		
		public static function sineFromSlope(tan:Number):Number{
			return Math.sin(Math.atan(tan));
		}
		
		public static function cosineFromSlope(tan:Number):Number{
			return Math.cos(Math.atan(tan));
		}
		
		//Find a maximum value within an array
		public static function getMaximum(array:Array):Number{
			var index:int = 0;
			var max:Number = array[index];
			for (var i:int = 1; i< array.length; i++){
				if (array[i] > max){
					index = i;
				}
			}
			return index;
		}
		
		//Find a minimum value within an array
		public static function getMinimum(array:Array):Number{
			var index:int = 0;
			var min:Number = array[index];
			for (var i:int = 1; i< array.length; i++){
				if (array[i] < min){
					min = array[i];
					index = i;
				}
			}
			return index;
		}
	}
}